package com.lzz.log.helper;


import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.RequestParam;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.HashSet;

public class ClassUtil {

    private static final Set<Class<?>> PRIMITIVE_WRAPPERS = new HashSet<>(8);

    static {
        PRIMITIVE_WRAPPERS.add(Boolean.class);
        PRIMITIVE_WRAPPERS.add(Byte.class);
        PRIMITIVE_WRAPPERS.add(Character.class);
        PRIMITIVE_WRAPPERS.add(Short.class);
        PRIMITIVE_WRAPPERS.add(Integer.class);
        PRIMITIVE_WRAPPERS.add(Long.class);
        PRIMITIVE_WRAPPERS.add(Float.class);
        PRIMITIVE_WRAPPERS.add(Double.class);
        PRIMITIVE_WRAPPERS.add(Void.class); // 包括 Void 以保持完整性
    }

    public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
        return clazz.isPrimitive() || PRIMITIVE_WRAPPERS.contains(clazz);
    }


    public static MethodParameter getMethodParameter(Method method, int i) {
        return new MethodParameter(method, i);
    }

    public static <A extends Annotation> A getAnnotation(MethodParameter methodParam, Class<A> annotationType) {
        A parameterAnnotation = methodParam.getParameterAnnotation(annotationType);
        return AnnotationUtils.getAnnotation(parameterAnnotation, annotationType);

    }
}

